package com.gt.web.srv.utils;

import cn.hutool.core.util.StrUtil;
import org.apache.commons.lang3.StringUtils;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

/**
 * <p>
 * PuStrUtils
 * </p>
 *
 * @author: WeiHuan
 * @version:1.0
 * @date: 2024/2/20 22:01
 * 注意：本内容仅限于公司内部传阅，禁止外泄以及用于其他的商业目的
 */

public class PuStrUtils {

    /**
     * <p>
     *     删除换行符
     * </p>
     * @param printLine
     * @return
     */
    public static String removeLineFeed(String printLine) {
        if (StringUtils.isBlank(printLine)) {
            return printLine;
        }
        return printLine.replaceAll("\n|\r", " ");
    }
    public static String parseUser(String createUser) {
        if (StrUtil.isBlank(createUser)) {
            return "";
        }
        String[] s = createUser.split("_");
        String user = "";
        if (s.length>1){
            user = s[0]+"|"+s[1];
        }
        else {
            user = s[0];
        }
        return user;
    }
    public static LocalDateTime startTime() {
        LocalDateTime start = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
        return start;
    }
    public static LocalDateTime endTime() {
        LocalDateTime end = LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
        return end;
    }

    /**
     *
     * @param str
     * @return
     */
    public static LocalDateTime str2LocalDateTime(String str) {
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        return LocalDateTime.parse(str, df);
    }
}